﻿namespace ImageCrawler
{
    internal class Program
    {
        static async Task Main(string[] args)
        {
            await main();
        }

        static async Task main()
        {
            Console.WriteLine("Hello, World!");


            Console.WriteLine("=== C# 图片爬虫工具 ===");
            Console.WriteLine();

            // 获取用户输入
            Console.Write("请输入要爬取的网站URL: ");
            string? url = Console.ReadLine();

            if (string.IsNullOrWhiteSpace(url))
            {
                Console.WriteLine("URL不能为空！");
                return;
            }

            Console.Write("请输入要搜索的关键字（多个关键字用逗号分隔）: ");
            string? keywordsInput = Console.ReadLine();

            //if (string.IsNullOrWhiteSpace(keywordsInput))
            //{
            //    Console.WriteLine("关键字不能为空！");
            //    return;
            //}

            Console.Write("请输入图片保存路径（默认: ./downloads）: ");
            string? savePath = Console.ReadLine();
            savePath = string.IsNullOrWhiteSpace(savePath) ? "./downloads" : savePath;

            // 创建爬虫实例
            var crawler = new ImageCrawler(url, keywordsInput.Split(','), savePath);

            try
            {
                Console.WriteLine($"开始爬取: {url}");
                Console.WriteLine($"关键字: {keywordsInput}");
                Console.WriteLine($"保存路径: {savePath}");
                Console.WriteLine(new string('-', 50));

                await crawler.StartCrawling();

                Console.WriteLine("爬取完成！");
            }
            catch (Exception ex)
            {
                Console.WriteLine($"发生错误: {ex.Message}");
            }
        }
    }
}
